# -*- coding: UTF-8 -*-

import pymysql
from HouseData import settings

Host = '127.0.0.1'
User = 'root'
Password = ''
dbname='ShenzhenRealestate'

db = pymysql.connect(Host,User,Password,dbname,charset="utf8")
cursor = db.cursor()

class Sql:
    @classmethod
    def Insert_House(cls,Id,Region,Garden,Layout,Size,Direction,Renovation,Elevator,Price):
        sql = "INSERT INTO  House(Id,Region,Garden,Layout,Size,Direction,Renovation,Elevator,Price) VALUES(%(Id)s,%(Region)s,%(Garden)s,%(Layout)s,\
        %(Size)s,%(Direction)s,%(Renovation)s,%(Elevator)s,%(Price)s )"

        value = {
            'Id':Id,
            'Region': Region,
            'Garden':Garden,
            'Layout':Layout,
            'Size':Size,
            'Direction':Direction,
            'Renovation':Renovation,
            'Elevator':Elevator,
            'Price':Price
        }

        cursor.execute(sql,value)
        db.commit()
    @classmethod
    def Select_id(cls,Id,Region):
        sql="SELECT EXISTS(SELECT 1 FROM House WHERE Id=%(Id)s AND Region=%(Region)s)"
        value={
            'Id':Id,
            'Region':Region
        }
        cursor.execute(sql,value)
        return cursor.fetchall()[0]